package com.shaw.workrecord.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shaw.workrecord.dto.SystemUser;
import com.shaw.workrecord.mapper.SystemUserMapper;
import com.shaw.workrecord.pojo.SystemUserVO;
import com.shaw.workrecord.pojo.request.SystemUserRequest;
import com.shaw.workrecord.service.ISystemUserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author jh.jiang
 * date 2022-08-13
 * description
 */
@Service
public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemUser> implements ISystemUserService {

    @Override
    public List<SystemUserVO> getUsers() {
        List<SystemUser> userList = baseMapper.getUserList();
        return BeanUtil.copyToList(userList, SystemUserVO.class);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean register(SystemUserRequest request) {
        SystemUser systemUser = BeanUtil.copyProperties(request, SystemUser.class);
        systemUser.setPhone(request.getAccount());
        int result = baseMapper.insert(systemUser);
        return result > 0;
    }
}
